Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    innerHTML resolving relative paths (IE only)

    i am having a problem when setting the innerHTML of a div with html that contains an img tag. the img tag contains a relative path in the src when i set the innerHTML but when i grab the value it has resolved it to the full url. this only happens in IE6.0 (well i've only tested that and firefox but i only need it to work in IE).

    Code:
    <script>
    function Test()
    {
    	var xElem = document.getElementById( "testing" ) ;
    	var sHTML = "<img src=\"/content/images/blank.jpg\" />" ;
    	alert( sHTML ) ;
    	xElem.innerHTML =  sHTML ;
    	alert( xElem.innerHTML ) ;
    }
    </script>
    
    <div id="testing"></div>
    <input type="button" value="test" onclick="Test()">
    what i want is for the paths to not resolve ie. stay the same as when i set it. instead i get <img src="http://localhost/content/images/blank.jpg"/>. i tried using the DOM methods (createTextNode, appendChild, etc) and i see the same results. i've searched and searched and can't find an answer...any help is greatly appreciated!

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    It may help to keep the url relative.
    Try using a src url without the opening root slash. As you may or may not know, the root slash acts as shorthand for the full domain. A url with a root slash is effectively an absolute url, which is probably what IE is picking up on.

    Alternatively, you could check the url string value returned for the presence of the domain string and, if present, split it into an array, taking just the part you need.
    If the domain isn't present in the url string, then you should be able to take the url string value directly.

    http://www.pageresource.com/jscript/jstring2.htm

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for your suggestions. i tried using the relative path "content/images/blank.jpg" but it still resolved the path to the full url. i thought about doing the domain replace but i'd rather not have to look for it. the app will go on different systems (dev, staging, production) and i'd hate to add code to allow us to specify which domain to look for on a specific system just for this. i just don't understand why IE wants to resolve the path...shouldn't the property just take the html i assign it and not touch it?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    nomatter which method you will use do get the url of an element, the result will be always the full url, not the relative. But why does it bother you? Why do you need the relative? What to do with it?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem is that the app doing the changing is under one domain and the html will appear in another domain. i'm trying to create a simple app to allow some users to update a portion of a webpage in an editor (editor is in www.domain1.com and html will appear in www.domain2.com). i wouldn't expect either method to change the underlying html by resolving the paths for me. firefox doesn't have this behavior. if you take my code and run it on your machines, do you get the same results as i do?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •