Opening url with schema appended in new window Javascript - javascript

I have the URL of an uploaded file like this,
"http://localhost/App/uploads/image1.png"
I need to append the string "pic.scheme://" at the beginning of this url and open in new window.
When I try to open this in new window, missing the : from "pic.scheme://" in the address bar.
What I need is:
"pic.scheme://http://localhost/App/uploads/image1.png"
What am getting is: "pic.scheme//http://localhost/App/uploads/image1.png"

Related

how to open url in new window without appending local url

let url = "www.w3schools.com"
{url}
I am trying to open url in the new tab but i am getting http://localhost:9998/www.w3schools.com in the new window instead of https://www.w3schools.com/
let url = "https://www.w3schools.com"
{url}
You need to specify the protocol as well, or the URL will be treated as relative.

How to save the second web page in browser using vb.net

I am opening a new tab in the browser and i want to save the page in html format.
My code is :
Page.ClientScript.RegisterStartupScript(Me.[GetType](), "OpenWindow", "window.open('https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=stack+overflow','_newtab');", True)
Here am opening a new window.Now i want to save the new web page in the html format. Please help me how to save the web page in new opened tab.
If you want to capture the response from a given URL server-side and save it to a file on the server, you can do something like this, using the WebRequest class:
Dim request As WebRequest = WebRequest.Create("http://www.example.com")
Using response As WebResponse = request.GetResponse()
Using reader As New StreamReader(response.GetResponseStream())
Dim html As String = reader.ReadToEnd()
File.WriteAllText("test.html", html)
End Using
End Using

Save image from given URL and print it in JavaScript

Here is my issue: on my webpage I'm displaying an image that been taken from a given URL (the image been display in a div).On the backhand I'm setting up the URL with all the information.
Beside the fact that I'm showing the picture I want to print the page - means print the div with all the content...Now when I'm trying to print Because of the image that been take from the given URL I'm getting empty place where the image should be.
In order to solve it I figure it out that I need to do something in the background to save the image from the given URL so I have this code below.... How can I send what I'm getting from function to JS Code in order to combined the missing part when I print????
If someone have other solution please help me....
The URL of the Image : https://freemobilewallpaper.files.wordpress.com/2009/10/kuala3.jpg
JS Function:
//============================== //
// Print Map//
// ============================== //
function printDiv() {
How Can I print what been set in the code behind?????##!#
var test = document.getElementById("<%= divRightWrapper.ClientID %>");
document.body.innerHTML = test;
var newWin = window.open();
newWin.document.write(test.innerHTML);
newWin.print();
}
Back Code:
Dim img As Image = GetPicture(urll)
How to send it to JS?????!##$!
Private Function GetPicture(ByVal url As String) As Image
Try
url = Trim(url)
If Not url.ToLower().StartsWith("http://") Then url _
= "http://" & url
Dim web_client As New WebClient()
Dim image_stream As New _
MemoryStream(web_client.DownloadData(url))
Return Image.FromStream(image_stream)
Catch ex As Exception
End Try
Return Nothing
End Function
Basic solution:
Use a printable version page and then popup a window with that page.
I think you can pass 64base encoded version of image.
Check this:
Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?

Java Download file from url with download dialog

I want to download a file from a url which initially shows some html, then displays a download dialog after 2-3 seconds. Obviously if I do this:
try {
URL url = new URL("http://my.url");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Length",
Integer.toString(Integer.MAX_VALUE));
con.setReadTimeout(Integer.MAX_VALUE);
con.setConnectTimeout(Integer.MAX_VALUE);
con.connect();
bis = new BufferedInputStream(con.getInputStream(), 4096);
byteArray = IOUtils.toByteArray(bis);
FileUtils.writeByteArrayToFile(new File("myFile"), byteArray);
} catch (Exception e) {
}
I will save the displayed .html rather than the file that is displayed in the save dialog.
How should I change the code in order to do this?
I'm guessing the dialog just has some javascript which waits a couple seconds and requests the file download embedded in the dialog somewhere.
If this is the case, if you figure out what element the 'real download' is contained in, you can use JSoup, or any other html parser library to scrape the link out of the page.
You obviously only have to do that if the download link is generated dynamically.
After doing what rossa suggests, I'd suggest setting javascript breakpoints in the dialog window to figure out how exactly the real url is getting requested.
Are you sure the url is the exact location of the file you want to download? I mean, is there any redirect - you can check in your browser and use HTTP headers extension for instance to check what's going on behind the scene.

Open a new window on response with pdf attachment

jqGrid('navButtonAdd',"#pager2",{caption:"Save All",title:"Save & Create Receipt",onClickButton:function () {
var s;
s = jQuery("#list2").jqGrid('getDataIDs');
alert("selected");
$.ajax({
type: 'POST',
url:'http://localhost:3000/order/receipt',
data: {ids: s},
});
}});
With above code, I'm able to submit data to server and the on server side it will generate a pdf as attachment, now I want to view the pdf on response via a new window/tab on browser.
Anyway to do it?
thanks,
lupind
If you return a URL to the just generated PDF then you can call window.open with that URL. But I wouldn't use an Ajax call if you want to open a new window to display the PDF anyway. In this case I would either:
Use Javascript's window.open passing
through the data in the URL to the
page that generates the PDF and let
it output to the browser's window
(but it might be too much data in the
URL)
Create a special form to hold
the data from your page and submit
that form. This special form would
have a target attribute set
(target="_blank") to open it in a new
window/tab.
For me, using two HTTP calls for one result (the generation and viewing of a PDF) is a waste.
You can use window.open() to open a new window with a specified URL. Be careful, though, only to do this when necessary.
Excerpt from this link.
Use an iframe with visibility:hidden, then change the iframe location to a downloadable file in javascript on the success callback.
var iFrame = document.getElementById('hiddenIFrame');
iFrame.src = theurlThatWillProduceTheFile;

Categories