Skip to main content
March 24, 2008
Question

XMLHTTPRequest, is it possible?

  • March 24, 2008
  • 1 reply
  • 334 views
For now I simply want to know if its possible.

I want to write an extension, that when a user clicks on a button it requests a web page from their domain, and copys the contents into their currently opened document.
This topic has been closed for replies.

1 reply

March 30, 2008
I'm guessing here because I don't have my references with me, but you should be able to do that. You should probably use a command menu item for this.

Create the menu command by first creating an html page. Between the document's <title></title> tags, enter the name of the command you want to appear in the "Commands" menu (i.e. "Get web page contents"). Save the page to your "Configurations/commands" folder using the same name. Create a ".js" file with the same name as the html file, save it to the same folder and link it to the html page.

In the ".js" file be sure to write the "canAcceptCommand()" function to return a value of true if there is an active document (DOM). Like this...

function canAcceptCommand() {
(dw.getDocumentDOM) ? return true : return false;
}

I'm not sure if that's entirely correct, so double-check that.

Then in the document's <body> tag, add the "onload" event to call the function to perform the task. Ex:

<body onload="getURL()">

Then in your script file, write the function to read or open the web page. Of course, I think this will open it as a new document and not add it to the current one. You may need to perform some type of "setSelection()" or "selectAll()" to replace the contents of the current document if one is open. It may be easier to open it as a new file rather than pasting it inside an opened one.

function getURL() {
var theDOM = dw.getDocumentDOM(' http://www.thepage.com');
var strFile = DWfile.read(theDOM);
DWfile.open(strFile);
}

After you save the file in the "commands" folder, restart Dreamweaver and you should see a new selection at the bottom of the "Commands" drop-down menu. If the code is correct, then selecting the menu item should open and read in the web page.

I'm still learning all the neuances of extensions, so my examples are probably wrong. But it's a starting point.

Hope this helps.