Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to write domain independant IMG tags?
Old 06-23-2011, 02:21 AM How to write domain independant IMG tags?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
I want to write a JQuery script that it inserts an image before a DIV.

But can't figure out a way to write it so that the domain of the URL
isnt hard coded.

see below:

Code:
$(document).ready(function(){
   
    $('<a href="http://anothersite.com">
<img src="http://mysite.com/images/transparent.gif" />
</a>').insertBefore('div.player');
            
    };
            
});
That works fine. But if the domain moves it will break.
I wonder if there is some kind of jQuery placeholder for the
current domain?

Maybe use something like this?
Quote:
var pathname = window.location.pathname;
and explode it using slashes?
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 06-23-2011 at 02:24 AM..
TWD is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2011, 08:29 AM Re: How to write domain independant IMG tags?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Couldn't you just use relative paths? Like

EDIT: The first example was suppose to be "../images/transparent.gif", but the forum keep adding the forum address when I post it

HTML Code:
<img src=../images/transparent.gif">
or
HTML Code:
<img src="/images/transparent.gif">
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by chrishirst; 06-23-2011 at 09:45 AM..
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-23-2011, 09:43 AM Re: How to write domain independant IMG tags?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Or use root relative paths

HTML Code:
 <img src="/includes/images/folder/image.ext" alt="" />
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-23-2011, 09:47 AM Re: How to write domain independant IMG tags?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
The first example was suppose to be "../images/transparent.gif", but the forum keep adding the forum address when I post it
To stop that happening uncheck the "Automatically link URLs in post in the "Advanced" post interface.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-23-2011, 10:54 AM Re: How to write domain independant IMG tags?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Or use root relative paths

HTML Code:
 <img src="/includes/images/folder/image.ext" alt="" />
Will give that another try but I think I did that before and couldnt get it to work.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to How to write domain independant IMG tags?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.67486 seconds with 12 queries