Getting URL From an OBJECT HTML tag

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
Corey080698Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knightEknightCommented:
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
Corey080698Author Commented:
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
gegegeCommented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Corey080698Author Commented:
An example would be great!
0
knightEknightCommented:
<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
gegegeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gegegeCommented:
3 - the reason for the MyLink=1 thing is so you can have your own links on the page etc.
0
Corey080698Author Commented:
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
gegegeCommented:
ie or netscape?  (both??) what html do you get mis-displayed?
0
Corey080698Author Commented:
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
gegegeCommented:
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
Corey080698Author Commented:
Thanks gegege...I modified your code to get this to work so you get the points!
0
gegegeCommented:
just out of interest, what did you end up with?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.