/    Sign up×
Community /Pin to ProfileBookmark

help with using location.pathname..

new to javascript.. needs some help.

if the full URL is..

abc.xyz.com/haha/hehe.html

i only want to extra hehe.html, but location.pathname locates haha/hehe.html.. how do i do the way i want? or I dont..

thanks in advance.

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonMay 07.2004 — Try this:

<i>
</i>
location.pathname.substring(location.pathname.lastIndexOf("/"),location.pathname.length);

Copy linkTweet thisAlerts:
@kodeikoauthorMay 07.2004 — hey, thanks alot..

but now i have another problem which i am sorry that i failed to mention in my original post.

if i have ..

abc.xyz.com/haha/hoho/hehe.html

i want to extract hoho/hehe.html out.. like i just want the strings after /haha/ to appear, any idea?

my apologies and thanks in advance.
Copy linkTweet thisAlerts:
@David_HarrisonMay 07.2004 — OK then :rolleyes: Try this:

<i>
</i>
location.pathname.substring(location.pathname.lastIndexOf("/",location.pathname.lastIndexOf("/")),location.pathname.length);

(May not work, I could be bothered checking it, tired.)
Copy linkTweet thisAlerts:
@kodeikoauthorMay 08.2004 — OK, so it didn't really work the way I wanted..

LoL, thanks anyway. :-) Appreciate your help.
Copy linkTweet thisAlerts:
@AdamGundryMay 08.2004 — How about this:

location.pathname.match(/haha/(.*)/i)[1]
Adam
Copy linkTweet thisAlerts:
@kodeikoauthorMay 08.2004 — Thanks Adam, you're the man.

But just curious if there's a way to stop the "javascript error" from popping out in IE whenever I try to run the page locally - from a folder instead of a URL?
Copy linkTweet thisAlerts:
@David_HarrisonMay 08.2004 — Well on a local machine it uses backslashes rather than forward slashes so this should work I [i]think[/i]:

<i>
</i>
if(location.pathname.indexOf("/")){

location.pathname.match(/haha/(.*)/i)[1]

} else {

location.pathname.match(/haha\(.*)/i)[1]

}

Copy linkTweet thisAlerts:
@starrwriterMay 09.2004 — [i]Originally posted by lavalamp [/i]

[B]Well on a local machine it uses backslashes rather than forward slashes so this should work I [i]think[/i]:



<i>
</i>
if(location.pathname.indexOf("/")){

location.pathname.match(/haha/(.*)/i)[1]

} else {

location.pathname.match(/haha\(.*)/i)[1]

}

[/B][/QUOTE]


That looks close to what I have been looking for the past few weeks.

I want the insert image function to insert the relative image path (rather than the absolute path) when the user of my WYSIWYG editor browses an image from his hard drive. So that the image tag ends up: img src="photo1.jpg" instead of img src="C:/Windows/Desktop/Images/photo1.jpg"

Any ideas?
Copy linkTweet thisAlerts:
@David_HarrisonMay 09.2004 — How can we possibly help you if we can't see the editor? IIRC what you also keep failing to mention is that this is not a program, it's in an HTML document.
Copy linkTweet thisAlerts:
@AdamGundryMay 09.2004 — You could do this:

location.pathname.match(/haha[/\](.*)/i)[1]
Adam
Copy linkTweet thisAlerts:
@starrwriterMay 11.2004 — [i]Originally posted by lavalamp [/i]

[B]How can we possibly help you if we can't see the editor? [/B][/QUOTE]


This is the insert image function in the browser-based WYSIWYG editor for IE5.5+:

function insImg() {

iView.focus();

iView.document.execCommand('insertimage', true, null);

}

The toolbar button that launches this function opens an IE modal dialog. But the dialog automatically uses the absolute image path in the image tag.

iView is the iframe that serves as an editing window for the editor.
Copy linkTweet thisAlerts:
@David_HarrisonMay 11.2004 — It sounds like all that needs to be done is a bit of code needs deleting (the bit that puts in the whole path for the image), upload it or give a link to it in a new thread and I'll see what I can do. Send me a PM in case I don't see it in the forums.
Copy linkTweet thisAlerts:
@starrwriterMay 12.2004 — [i]Originally posted by lavalamp [/i]

[B]It sounds like all that needs to be done is a bit of code needs deleting (the bit that puts in the whole path for the image[/B][/QUOTE]


There is no code to delete. execCommand(insertimage, true) automatically opens the IE modal dialog. That is not part of my code and I can't access it to change it. It's a proprietary feature of Microsoft's edit function.

While the editor is being used, the image path must be absolute so the image is displayed in the editing window when the user inserts it. I need to ADD code to change the image path from absolute to relative when the web page under construction is saved. The solution is a few lines of script in the save function, but no one seems to have a clue.

This is the save function:

function saveFrame() {

var html = iView.document.documentElement.outerHTML;

iView.document.write(html);

iView.document.execCommand('SaveAs');
×

Success!

Help @kodeiko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...