?
Solved

How to make javascript detect addressbar

Posted on 2009-04-22
10
Medium Priority
?
266 Views
Last Modified: 2012-05-06
I'm trying to develop javascript + ajax that will detect addressbar value.Lets say if it's a "www.first.com" it will load content via ajax from "127.0.0.1/first/" and if addressbar value is "www.second.com" it will load content via ajax from "127.0.0.1/second/".Can some one tell me how this can be acheived?
0
Comment
Question by:Maranellas
  • 4
  • 4
  • 2
10 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24203711
yes, you can try:



if(location.href.indexOf("www.first.com") >= 0)
{
    // do something with first.com
} else if (location.href.indexOf("www.second.com") >= 0)
{
    // do something with second.com
}

Open in new window

0
 
LVL 3

Expert Comment

by:SPARC-DESIGN
ID: 24204554
Hey,
this should do the trick

var url = window.location.hostname.substring(window.location.hostname.indexOf(".")+1, window.location.hostname.indexOf(".com"));
 
window.location="http://127.0.0.1/" + url;

Open in new window

0
 

Author Comment

by:Maranellas
ID: 24207019
abel,how can i make ajax automaticaly load page into iframe without redirecting to new location?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Expert Comment

by:abel
ID: 24207181
That's an entirely different issue...

Well, that's highly dependent on what AJAX libs you are using and then stil. It is not easy, because AJAX is all about NOT using iframes. From an AJAX call you receive XML content back, which needs to be processed and needs to be put into the DOM somehow. If you're new to this, it is probably best to first read a few tutorials, as AJAX is quite a complex concept.
0
 
LVL 3

Expert Comment

by:SPARC-DESIGN
ID: 24207225
http://docs.jquery.com/Ajax/jQuery.ajax#options

Ajax doesn't need to be complex...

$("#a_div").load("your_page_to_load.php");

a_div is the ID of the div (or other tag) you want to put the data in
0
 
LVL 39

Expert Comment

by:abel
ID: 24207381
> Ajax doesn't need to be complex...
I agree, but it is, regardless. Luckily, tens of libs help us out nowadays. The OP asked to put the output in an IFrame, and that's where it gets tricky because you cannot set the iframe's content with HTML you generated on the fly. You can only set the source to point to a URL, but then you do not need AJAX anymore...
0
 
LVL 3

Expert Comment

by:SPARC-DESIGN
ID: 24207411
@ abel,

true, that's why I suggested the use of a DIV
0
 

Author Comment

by:Maranellas
ID: 24212432
ok then what about javascript if i use the function to navigate iframe to certain url?I need website as more dynamic as possible
0
 
LVL 3

Accepted Solution

by:
SPARC-DESIGN earned 2000 total points
ID: 24212495
hi,
if you want to change the url of an iFrame, use this code

function handleIFRAME(url){ 
     
    var iframe = document.getElementById('yourIframeId'); 
 
    iframe.src = url; 
    iframe.reload();     
 
} 

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24213296
> ok then what about javascript if i use the function to navigate iframe
> to certain url?I need website as more dynamic as possible


you seem to be drifting further and further from your original question (remember that EE is about asking one question and then working towards a solution).

Before we try to solve every new idea, maybe it's a good idea what you are after, what languages you are using (and which of them you know or have trouble with) and what functionality you want. Just saying "I want it as dynamic as possible" is too vague and is better suited in the Design Patterns zone of EE.

Please read the following (esp. the first tip: http://www.experts-exchange.com/questionTips.jsp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question