JQuery Not Parsing Properly attr ("href") in IE

I have a really weird problem that I hope someone can shed some light on. I am using jquery to get an Http response from another site (which I have). When I get the DOM, I parse it to get specific information. However, when I try to get the href attribute of a link, IE adds the local domain to the top of href!

Here is my code:

$.ajax({ 
                    type: "POST",
                    url: "MyPage.aspx/GetWebResponse",
                    data: "http://myWebSite/pages/AnotherPage.aspx",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    asynch: false,
                    success: function(data)
                    {
                        var __htmlForMainPage = data.d;                   


                        var PageLink = $(__htmlForMainPage).find("a:contains('Get This Link')").attr("href"); 
                                                }   
                });

My PageLink variable MUST be "/pages/getThisPage.aspx?id=8347". However, it returns as " http: //myserver/pages/getThisPage.aspx? Id = 8347 ".

IE. FireFox . , . , , IE, FF. , FF , IE .

- , ? !

+5
5

href DOM A IE URL-. getAttribute() IE7 ( getAttribute IE8).

http://msdn.microsoft.com/en-us/library/cc848861(VS.85).aspx:

Internet Explorer 8 . IE8 HREF . (DOM) HREF URL- , -. HREF , , . . " " Internet Explorer 8.

jQuery DOM, :

// If applicable, access the attribute via the DOM 0 way
if ( name in elem && notxml && !special ) {
    // ...
}

name in elem , DOM. IE8, - .attr("HREF") - DOM . , IE7 :

var base = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1);
PageLink = PageLink.replace(base, ""); 
+9
+2

"" , , HTML, , jQuery "" DOM-Tree.

, IE, , URL- a- DOM ( , , URL-, , URL-).

jQuery , DOM-.

, Firebug! DOM ( IE8 IE - ).

+1

URL. URL- - . :

var urlParts = /^(https?:\/\/.+?)?(\/.+?)(\?.*?)?$/.exec(href);
var server = urlParts[1]; // maybe be '' depending on the browser
var path = urlParts[2];
var query = urlParts[3];

, " +".

0

Pass the second attribute to the getAttribute function:

linkobj.getAttribute(β€˜href’,2);

Read more here http://glennjones.net/2006/02/getattribute-href-bug/

0
source

All Articles