Solved

Getting URL From an OBJECT HTML tag

Posted on 2002-06-14
13
260 Views
Last Modified: 2008-02-01
Hello All,

  I'm working on a school assignment.  We are to create an eBay snipe tool (something that submits a bid at the last possible second before the auction ends).  One of the fucntions I need to provide is the ability to browse eBay and have the ability to have a button which will grab the auction ID number from the current item they want to bid on.  As we are not allowed to use the FRAME or IFRAME tag, I loaded eBay in an OBJECT tag and now need to be able to grab the URL from the object.  Out of the URL I can parse the ID number but everytime I try to get the URL, i only get the www.ebay.com and not the part with the ID number.  Here is my code...



<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--

function GetAuctionNumber()
{
    GetNumber.TEST.value = eBay.data;
}

//-->
</SCRIPT>
</HEAD>
<CENTER>
<FORM TYPE="POST" NAME="GetNumber">
     <INPUT NAME="TEST" TYPE="TEXT" VALUE="">
     <BR><BR>
    <INPUT TYPE="BUTTON" VALUE="Get Auction Number" onClick="javascript:GetAuctionNumber()">
</FORM>

<OBJECT ID="eBay" DATA="http://www.ebay.com" WIDTH="675" HEIGHT="400">
     Cannot display eBay at this time...
</OBJECT>

</CENTER>
</BODY>
</HTML>

Any Suggestions?

Corey
0
Comment
Question by:Corey080698
  • 6
  • 5
  • 2
13 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
can you open another browser?

if so then you can parse the URL of the second browser.

1).  Open new window to ebay:

  var newwin = window.open("www.ebay.com","newwin");

2).  When the user browses to the page they want in the new window, then they hit the Get Auction Number button, which retrieves the URL of the new window and parses it:

  var idstr = newwindow.location.search;
  alert(idstr);
0
 

Author Comment

by:Corey080698
Comment Utility
Unfortunately we can't...it has to be "integrated" into our software...which means no Windows...they've gone out of their way to make this hard :o)
0
 
LVL 1

Expert Comment

by:gegege
Comment Utility
Your not going to be able to do it with JavaScript alone, you will need to write an activex control which can load the page, either using the webbrowser control, or you could open the page in script and use the shellwindows collection in shdocvw to find the right version of IE then use the Ie object to get to the document eg ie.document.body will get to the usual body section.

Let me know if you want a sample of this in vb.

The reason it won't work is to do with security, as you can't access pages in different domains (at least you shouldn't be able to)
0
 

Author Comment

by:Corey080698
Comment Utility
An example would be great!
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
<HTML>
<HEAD>
<SCRIPT language='JavaScript'>

 function include(url)  // must be a fully qualified URL, I don't know why
 {
   if ( document.all )
   {
     var xml = new ActiveXObject("Microsoft.XMLHTTP");
     xml.Open( "GET", url, false );
     xml.Send()
     document.writeln(xml.responseText);
   }
   else  // Netscape code by itzsuresh taken from http://www.experts-exchange.com/javascript/Q.20290896.html
   {
     if ((location.host == '' && url.indexOf(location.protocol) == -1) || url.indexOf(location.host) == -1)
     {
       netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");
     }

     var dest = new java.net.URL(url);
     var dis  = new java.io.DataInputStream(dest.openStream());
     var res  = "";
     while ((line = dis.readLine()) != null)
     {
       res += line + java.lang.System.getProperty("line.separator");
     }
     dis.close();
     document.writeln(res);
   }
 }

</script>
</head>

<BODY onLoad='alert(document.all.test.InnerHTML);'>
Included file:<BR>

<div id="test">
<SCRIPT language='JavaScript'>
   include("http://www.ebay.com");
</script>
</div>

</body>
</html>
0
 
LVL 1

Accepted Solution

by:
gegege earned 200 total points
Comment Utility
ok - I have modified knightEknights example because it gave me some ideas:

<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
var CurrentUrl;
var xmlHttp = null;

function GetCurrentItem(){
     
var myRe = new RegExp();
myRe = /item=*/g;
myArray = myRe.exec(CurrentUrl);

if(!myRe.lastIndex <= 0)
     {
     return CurrentUrl.substr(myRe.lastIndex, (CurrentUrl.length - myRe.lastIndex));
     }else
          return "The Page does not have an auction item associated with it.  (or eBay has changed their querystrings)"

}

function GetUrl(url)  // must be a fully qualified URL, I don't know why
{
CurrentUrl = url

  if ( document.all )
  {
     dvThePage.innerHTML = "Downloading Page...";
    xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
     
    xmlHttp.Open( "GET", url, true);
    xmlHttp.onreadystatechange = xmlStateChange;
    xmlHttp.Send();
 
   

//    return xml.responseText;
  }
  else  // Netscape code by itzsuresh taken from http://www.experts-exchange.com/javascript/Q.20290896.html
  {
    if ((location.host == '' && url.indexOf(location.protocol) == -1) || url.indexOf(location.host) == -1)
    {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");
    }

    var dest = new java.net.URL(url);
    var dis  = new java.io.DataInputStream(dest.openStream());
    var res  = "";
    while ((line = dis.readLine()) != null)
    {
      res += line + java.lang.System.getProperty("line.separator");
    }
    dis.close();
    dvThePage.innerHTML = res;
     FixLinks();
  }
}

function xmlStateChange(){

     if(xmlHttp.readyState == 4){
          dvThePage.innerHTML = xmlHttp.responseText;
          FixLinks()
     }else{
       try{    
          if(xmlHttp.readyState == 3){
               dvThePage.innerHTML = xmlHttp.responseText;
          }else{
               dvThePage.innerHTML += ".";
               }
               window.setTimeout("xmlStateChange()", 500);
          }catch(e){
         
          }
         
     }    
     
}

function ChangeUrl(Url) {
     var Page = GetUrl(Url);
     CurrentUrl = Url;
}

function FixLinks(){

     for(var i=0; i<document.links.length;i++) {
          if(document.links[i].MyLink != "1"){
               document.links[i].href = "javascript:ChangeUrl(\"" + document.links[i].href + "\")";
         
          }
     }

}

</Script>

<TITLE></TITLE>
</HEAD>
<BODY onLoad="ChangeUrl('http://www.ebay.com');">
<A href="www.yahoo.com"  MyLink="1">MyLink 1</A> || <A href="www.hotmail.com"  MyLink="1">MyLink 2</A>  ||  <INPUT TYPE="button" value="Get Item Number" onClick="alert(GetCurrentItem())">
<HR>
<P>&nbsp;</P>&nbsp;
<DIV
style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; LEFT: 190px; BORDER-LEFT: black thin solid; WIDTH: 572px; BORDER-BOTTOM: black thin solid; POSITION: absolute; TOP: 104px; HEIGHT: 581px" id="dvThePage">  </DIV>&nbsp;

</BODY>
</HTML>


What this does is download a page then display it in the DIV box - it then goes through all the links on the page and changes every one which doesn't have the value MyLink=1 and changes the link so instead of getting teh url it calls the GetCurl function which downloads the page and displays it in the div box so your users can browse to the auction item.

when you want to get the item number, the function GetItemNumber, checks to see if the url contains item= then retrieves the number.

things to note: 1 - I haven't tested it on netscape as I dont have it here, but i dont see any reason why it shouldn't work.
2 - there is no way for your users to navigate backwards or forwards so you might want to use an array to keep the urls they have been to and offer a backwards and a forwards button and do it yourself, calling the GetUrl with the url should work exactly as it does when it is called from the page.

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:gegege
Comment Utility
3 - the reason for the MyLink=1 thing is so you can have your own links on the page etc.
0
 

Author Comment

by:Corey080698
Comment Utility
Hey all, thanks for the suggestions but none seem to be working 100% for me, I either get errors or misdisplayed HTML.  I've tried to adjust the code to work but no luck...any suggestions?
0
 
LVL 1

Expert Comment

by:gegege
Comment Utility
ie or netscape?  (both??) what html do you get mis-displayed?
0
 

Author Comment

by:Corey080698
Comment Utility
Right now i'm testing in IE and its when you click search you are missing the search for text box and some little things like that...if it was anything else it woudln't matter but this is probably what they will do (Searching) and if the options not there it causes problems...
0
 
LVL 1

Expert Comment

by:gegege
Comment Utility
I can get the small search on the top right hand corner to work and the one on the left as well, but the advanced one will take a little longer - could you implement the search yourself?  If you wrote your own page to do it then checked the urls before you get them and if the url is the advanced search form re-direct them?


0
 

Author Comment

by:Corey080698
Comment Utility
Thanks gegege...I modified your code to get this to work so you get the points!
0
 
LVL 1

Expert Comment

by:gegege
Comment Utility
just out of interest, what did you end up with?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now